#!/usr/bin/env python
# -*- coding: utf-8 -*-

from string import Template

#user
s = {"weixin":"string","alipayName":"string","alipayNo":"string","bankName":"string","bankNo":"string","bankAccount":"string","intermediaryId":"int","intermediaryName":"string"};
#project
#s = {"id":"int","title":"string","brokerStr1":"string","personStr1":"string","discountStr":"string","costPrice":"string","introduction":"string","hotTip":"string","buildingId":"int","buildingName":"string","details":"string","comment":"string","mobileDetails":"string"};
#recommend
#s = {"id":"int","fullName":"string","unitPrice":"string","phoneNumber":"string","intentionalArea":"string","sumTotal":"string","buildingId":"int","buildingName":"string","type":"string","isSchoolRoom":"int","buyingTime":"string","intentionalRegion":"string","remarks":"string","userId":"int","userName":"string","userTel":"string","status":"int","instructions":"string","add_time":"DateTime","report_time":"DateTime","see_time":"DateTime","deal_time":"DateTime","sort_id":"int"};
#building
#s = {"id":"int","userName":"string","userPwd":"string","name":"string","contactName":"string","contactTel":"string","address":"string","position":"string","other":"string"};

#recommend2
#s = {"add_time":"DateTime","report_time":"DateTime","see_time":"DateTime","deal_time":"DateTime","sort_id":"int"}
#t = {"int":"OleDbType.Integer,4","string":"OleDbType.VarChar,255","textarea":"OleDbType.VarChar"}  #access
t = {"int":"SqlDbType.Int,4","string":"SqlDbType.NVarChar,255","textarea":"OleDbType.VarChar","DateTime":"SqlDbType.DateTime"}  #sqlserver


def getsType(st):
    return t.get(st);


#aspx
def getparse1():
     s1 = "";
     temp_aspx = '''<dl>
    <dt>内容标题</dt>
    <dd>
      <asp:TextBox ID="txt${v1}" runat="server" ${v2} sucmsg=" " />
      <span class="Validform_checktip"></span>
    </dd>
  </dl>''';
     code = Template(temp_aspx);
     for i in s:
         v2 = s.get(i);
         if v2 == "int":
             v2 = '''CssClass="input small" datatype="n"''';
         elif v2 == "DateTime":
             v2 = '''CssClass="input rule-date-input" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" datatype="/^\s*$|^\d{4}\-\d{1,2}\-\d{1,2}\s{1}(\d{1,2}:){2}\d{1,2}$/" errormsg="请选择正确的日期"''';
         else:
             v2 = '''CssClass="input normal" datatype="*2-100"''';
         aa = code.substitute({"v1":i,"v2":v2});
         s1 = aa + s1;
     print s1;


def getparse2():
     s1 = "";
     aspx_t1 = '''model.${v1} = txt${v1}.Text.Trim();\n''';
     aspx_t2 = '''model.${v1} = Utils.StrToInt(txt${v1}.Text.Trim(), 1);\n''';
     aspx_t3 = '''model.${v1} = Utils.StrToDateTime(txt${v1}.Text.Trim());\n''';

     for i in s:
         atype = s.get(i);
         if i == "id":continue;
         if atype == "int":
             code = Template(aspx_t2);
         elif atype == "DateTime":
             code = Template(aspx_t3);
         else:
             code = Template(aspx_t1);
         aa = code.substitute({"v1":i});
         s1 = aa + s1;
     print s1;

def getparse3():
     s1 = "";
     aspx_t1 = '''txt${v1}.Text = model.${v1};\n''';
     aspx_t2 = '''txt${v1}.Text = model.${v1}.ToString();\n''';
     aspx_t3 = '''txt${v1}.Text = model.${v1}.ToString("yyyy-MM-dd HH:mm:ss");\n''';

     for i in s:
         atype = s.get(i);
         if i == "id":continue;
         if atype == "int":
             code = Template(aspx_t2);
         elif atype == "DateTime":
             code = Template(aspx_t3);
         else:
             code = Template(aspx_t1);
         aa = code.substitute({"v1":i});
         s1 = aa + s1;
     print s1;

     

#aspx
#getparse1();
#aspx.cs
getparse2();
#aspx.cs getInfo
#getparse3();
